﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using NursingFormSystem.Model;
using DLL;
using DevExpress.Office.Utils;

namespace NursingFormSystem.KnowingAgreeBook
{
    public partial class HistoryAgreeBookNursing : DevExpress.XtraEditors.XtraForm
    {
        private gregn6Lib.GridppReport gpr_Feport = new gregn6Lib.GridppReport();//引用对象
        //DataTable patientDt = null;
        NursingFormRecord record = new NursingFormRecord();
        //WebReference2.FunctionAndPermissions funcService = new WebReference2.FunctionAndPermissions();
        NurFormsService.NursingForm formService = new NurFormsService.NursingForm();
        string[] Patient;//选前选中患者信息，数组，传入调用的form中
        public HistoryAgreeBookNursing(string[] PatientInfo)
        {
            InitializeComponent();
            Patient = PatientInfo;
            BeginDate.DateTime = DateTime.Now;
            endDate.DateTime = DateTime.Now;
            //bandedGridView1.PopulateColumns();
        }

        private void btn_Query_Click(object sender, EventArgs e)
        {
            string patientid = this.Patient[0].ToString();
            int  FormId  = (int)FormType.Knowing;
            string Select = @"
                              SELECT'' AS CheReason,'' AS CheYuFang,'' AS CheFaZheng,'' AS KanHuReason,'' AS KanHuYuFang,
                              NursingFormData,'' AS JiaShuYiJian,'' AS QianMing,'' AS YuHuanZheGuanXi,'' AS HuShiQianMing,'' AS RiQi
                              FROM NursingFormRecord where 
                               FormId={0}
                            ";
            // Select = string.Format(Select,patientid,BeginDate.DateTime,endDate.DateTime,FormId);-- patientid='{0}' AND  CreateTime>='{1}' AND CreateTime<='{2}'
            Select = string.Format(Select, FormId);
         DataTable tabItem= SqlHelper.ExecuteDataset(Select,System.Data.CommandType.Text).Tables[0];
         DataTable tab = tabItem.Clone();
         if (tabItem.Rows.Count > 0)
         {
             
             foreach (DataRow rw in tabItem.Rows)
             {
                 var NursingFormData = Convert.ToString(rw["NursingFormData"]);
                 // List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ss);
                 Knowing bg = new Knowing();
                 bg = XmlUtil.XMLToObject<Knowing>(NursingFormData, Encoding.UTF8);
                 #region //约束工具
                 //约束工具-原因
                 string YuanYin = bg.YueShuGongJu.YuanYin;
                 string[] array = YuanYin.Split('#');
                 YuanYin = "";
                 if(Convert.ToInt32(array[0])==1)
                 {
                     YuanYin = "躁动、";
                 }
                 else if (Convert.ToInt32(array[1]) == 1)
                 {
                     YuanYin += "神智异常、";
                 }
                 else if (Convert.ToInt32(array[2]) == 1)
                 {
                     YuanYin += "精神障碍、";
                 }
                 else if (Convert.ToInt32(array[3]) == 1)
                 {
                     YuanYin += "肢体制动、";
                 }
                 string YY_QiTa = bg.YueShuGongJu.YY_QiTa;
                 YuanYin += YY_QiTa;
                 //约束工具-预防
                 string CheYuFang = bg.YueShuGongJu.YuFang;
                 array = CheYuFang.Split('#');
                 CheYuFang = "";
                 if(Convert.ToInt32(array[0])==1)
                 {
                     CheYuFang = "拔管、";
                 }
                 if (Convert.ToInt32(array[1]) == 1)
                 {
                     CheYuFang += "自伤、";
                 }
                 if (Convert.ToInt32(array[2]) == 1)
                 {
                     CheYuFang += "伤人、";
                 }
                 if (Convert.ToInt32(array[3]) == 1)
                 {
                     CheYuFang += "坠床、";
                 }
                 if (Convert.ToInt32(array[4]) == 1)
                 {
                     CheYuFang += "肢体过度活动、";
                 }
                 string YF_QiTa = bg.YueShuGongJu.YF_QiTa;
                 CheYuFang += YF_QiTa;
                 //约束工具-并发症
                 string CheFaZheng = bg.YueShuGongJu.BingFaZheng;
                 array = CheFaZheng.Split('#');
                 CheFaZheng = "";
                 if (Convert.ToInt32(array[0]) == 1)
                 {
                     CheFaZheng = "皮肤红肿、";
                 }
                 if (Convert.ToInt32(array[1]) == 1)
                 {
                     CheFaZheng += "破溃、";
                 }
                 if (Convert.ToInt32(array[2]) == 1)
                 {
                     CheFaZheng += "起泡、";
                 }
                 if (Convert.ToInt32(array[3]) == 1)
                 {
                     CheFaZheng += "感染、";
                 }
                 string BFZ_QiTa = bg.YueShuGongJu.BFZ_QiTa;
                 CheFaZheng += BFZ_QiTa;
                 #endregion
                 #region//24小时看护

                 //意识障碍
                 string YiShiZhangAi = bg.ErShiSiXiaoShiKanHu.YiShiZhangAi;
                 string[] PrArray = YiShiZhangAi.Split('#');
                 YiShiZhangAi = "";
                 if (Convert.ToInt32(PrArray[0]) == 1)
                 {
                     YiShiZhangAi = "躁动、";
                 }
                 if (Convert.ToInt32(PrArray[1]) == 1)
                 {
                     YiShiZhangAi += "神智异常、";
                 }
                 if (Convert.ToInt32(PrArray[2]) == 1)
                 {
                     YiShiZhangAi += "精神异常、";
                 }
                 if (Convert.ToInt32(PrArray[3]) == 1)
                 {
                     YiShiZhangAi += "肢体制动、";
                 }
                 string YSZA_QiTa = bg.ErShiSiXiaoShiKanHu.YSZA_QiTa;
                 YiShiZhangAi += YSZA_QiTa;
                 //精神障碍
                 string JingShenZhangAi = bg.ErShiSiXiaoShiKanHu.JingShenZhangAi;
                 PrArray = JingShenZhangAi.Split('#');
                 JingShenZhangAi = "";
                 if (Convert.ToInt32(PrArray[0]) == 1)
                 {
                     JingShenZhangAi = "抑郁症、";
                 }
                 if (Convert.ToInt32(PrArray[1]) == 1)
                 {
                     JingShenZhangAi += "精神分裂、";
                 }
                 if (Convert.ToInt32(PrArray[2]) == 1)
                 {
                     JingShenZhangAi += "老年痴呆、";
                 }
                 string JSZA_QiTa = bg.ErShiSiXiaoShiKanHu.JSZA_QiTa;
                 JingShenZhangAi += JSZA_QiTa;
                 //年龄
                 string NianLin = bg.ErShiSiXiaoShiKanHu.NianLin;
                 PrArray = NianLin.Split('#');
                 NianLin = "";
                 if (Convert.ToInt32(PrArray[0]) == 1)
                 {
                     NianLin = "婴幼儿、";
                 }
                 if (Convert.ToInt32(PrArray[1]) == 1)
                 {
                     NianLin += "老年人>65岁、";
                 }
                 string NL_QiTa = bg.ErShiSiXiaoShiKanHu.NL_QiTa;
                 NianLin += NL_QiTa;
                 string KanHuReason = "";
                 if (!string.IsNullOrEmpty(YiShiZhangAi))
                 {
                     KanHuReason = "意识障碍：" + YiShiZhangAi;
                 }
                 if (!string.IsNullOrEmpty(JingShenZhangAi))
                 {
                     KanHuReason = "精神障碍：" + JingShenZhangAi;
                 }
                 if (!string.IsNullOrEmpty(NianLin))
                 {
                     KanHuReason = "年龄：" + NianLin;
                 }
                 //预防
                 string YuFang = bg.ErShiSiXiaoShiKanHu.YuFang;
                 PrArray = YuFang.Split('#');
                 YuFang = "";
                 if (Convert.ToInt32(PrArray[0]) == 1)
                 {
                     YuFang = "跌倒、";
                 }
                 if (Convert.ToInt32(PrArray[1]) == 1)
                 {
                     YuFang += "坠床、";
                 }
                 if (Convert.ToInt32(PrArray[2]) == 1)
                 {
                     YuFang += "自伤、";
                 }
                 if (Convert.ToInt32(PrArray[3]) == 1)
                 {
                     YuFang += "伤人、";
                 }
                 if (Convert.ToInt32(PrArray[4]) == 1)
                 {
                     YuFang += "自行离院、";
                 }
                 if (Convert.ToInt32(PrArray[5]) == 1)
                 {
                     YuFang += "自杀、";
                 }
                 string YF_QiTaPr = bg.ErShiSiXiaoShiKanHu.YF_QiTa;
                 YuFang += YF_QiTaPr;
                 //YuFang = YuFang.Substring(0, YuFang.Length - 1);
                 #endregion

                 string JiaShuYiJian = bg.JiaShuYiJian;
                 string QianMing = bg.QianMing;
                 string YuHuanZheGuanXi = bg.YuHuanZheGuanXi;
                 string HuShiQianMing = bg.HuShiQianMing;
                 string RiQi = bg.RiQi;
                 DataRow newRow=tab.NewRow();
                 newRow["CheReason"]=YuanYin;
                 newRow["CheYuFang"] = CheYuFang;
                 newRow["CheFaZheng"] = CheFaZheng;
                 newRow["KanHuReason"] = KanHuReason;
                 newRow["KanHuYuFang"] = YuFang;
                 newRow["JiaShuYiJian"] = JiaShuYiJian;
                 newRow["QianMing"] = QianMing;
                 newRow["YuHuanZheGuanXi"] = YuHuanZheGuanXi;
                 newRow["HuShiQianMing"] = HuShiQianMing;
                 newRow["RiQi"] = RiQi;
                 tab.Rows.Add(newRow);
             }
         }
          gridControl1.DataSource = tab;
        }

        private void btn_AddRecord_Click(object sender, EventArgs e)
        {
            AddAgreeBookNursing AddForm = new AddAgreeBookNursing(Patient);
            AddForm.ShowDialog();
        }

        private void bandedGridView1_DoubleClick(object sender, EventArgs e)
        {
            //bandedGridView1.GetRowCellValue
            string nodeName = bandedGridView1.GetRowCellValue(bandedGridView1.FocusedRowHandle, "YuHuanZheGuanXi").ToString();
        }

     
    }
}